<?php

class Admin_Model_Sentnotifications {

    private $_dbtable;

    public function __construct() {
        $this->_dbtable = new Admin_Model_DbTable_Sentnotifications();
    }

    /**
     * 
     * @param type $data
     * @return type
     */
    public function addNew($data) {
        return $this->_dbtable->insert($data);
    }

    /**
     * 
     * @return array
     */
    public function fetchAll() {
        $select = $this->_dbtable->select();
        $result = $this->_dbtable->fetchAll($select);
        $allArray = array();
        foreach ($result as $notify) {
            array_push($allArray, $this->convertDataIntoFormatedArray($notify));
        }
        return $allArray;
    }

    /**
     * 
     * @param type $insertId
     * @return type
     */
    public function getByInsertId($insertId) {
        $select = $this->_dbtable->select();
        $select->where("id = ?", $insertId);
        $result = $this->_dbtable->fetchAll($select);
        return $this->convertDataIntoFormatedArray($result[0]);
    }

    /**
     * 
     * @param type $data
     * @param type $id
     */
    public function update($data, $id) {
        $this->_dbtable->update($data, "id = $id");
    }

    /**
     * 
     * @param type $result
     * @return type
     */
    function convertDataIntoFormatedArray($result) {
        $newArray = array();
        $newArray['id'] = $result['id'];
        $newArray['name'] = $result['name'];
        $newArray['email'] = json_decode($result['email']);
        $newArray['sms'] = json_decode($result['sms']);
        $newArray['date'] = date('d-m-Y',$result['date']);
        return $newArray;
    }

    
    
    
}

